<?php
include("check.php");
include_once("../class/system_class.php");
include_once("../class/member_class.php");
include_once("../class/ulevel_class.php");
session_start();
header("Content-Type: text/html;charset=utf-8");
$_member=new member_class();
$my=$_member->getMemberbyID($_SESSION['ID']);
if ($_POST['Search']){
    $SearchContent=$_POST['SearchContent'];
    if ($SearchContent!=NULL){
        $SearchType=$_POST['SearchType'];
        if ($SearchType==1){
            #搜索会员编号
            $_SESSION['Search']="and nickname='".$SearchContent."'";
        }elseif($SearchType==2){
            #搜索姓名
            $_SESSION['Search']="and username='".$SearchContent."'";
        }
    }else{
        $_SESSION['Search']=NULL;
    }
}else{
    if ($_GET['page']==NULL){
        $_SESSION['Search']=NULL;
        $_SESSION['SearchTime']=NULL;
    }
}

#删除会员
if ($_POST['button2']){
    $cheuid_arr = $_GET['id'];
    $_member=new member_class();
    foreach ((array)$cheuid_arr as $id)
    {
        if ($_member->checkfman($id)){
            edit_delete_cl('member',$id);
        }else{
            $us=$_member->getMemberbyID($id);
            echo "<script language=javascript>alert('会员".$us['nickname']."下方已经安置了会员,删除失败.');window.location.href='?'</script>";
        }
    }
    echo "<script language=javascript>alert('删除会员完成.');window.location.href='?'</script>";
}

$rs=getMemberbyID($_SESSION['ID']);
if($_POST['button3']){
    $cheuid_arr = $_GET['id'];
    $_member=new member_class();
    $bonus_cl=new bonus_class();
    if($us=$_member->getMemberbyID($cheuid_arr)){
        if($me=$_member->getMemberbyID($_SESSION['ID'])){
            $up=$_member->getMemberbyID($us['fatherid']);
            //if($up['ispay']>=1){

            if ($us['bdid']==$me['id']){
                if ($us['ispay']==0){
                    $_ulevel_class=new ulevel_class();
                    $_ul=$_ulevel_class->getulevelbyulevel($me['ulevel']);
                    //			if($me['gwb']>=$us['lsk']*$_ul['yl23']/100&&$me['zsq']>=$us['lsk']*$_ul['yl24']/100){
                    //				$num=4;
                    //			}else{
                    if($me['zsq']>=$us['lsk']){
                        $num=2;
                    }
                    /*	if($me['gwb']>=$us['lsk']){
                            $num=1;
                        }elseif($me['gwb']+$me['zsq']>=$us['lsk']){
                            $num=2;
                        }elseif ($me['mey']>=$us['lsk']){
                            $num=3;
                        }*/
                    //		}

                    if ($num>0){
                        if($num==1){
                            $me_update['gwb']=$me['gwb']-$us['lsk'];
                        }elseif($num==2){
                            /*$yecha=$us['lsk']-$me['gwb'];
                            if($yecha>=0){
                                $me_update['gwb']=0;
                                $me_update['zsq']=$me['zsq']-$yecha;
                            }*/
                            $me_update['zsq']=$me['zsq']-$us['lsk'];
                            $syzsq=$us['lsk'];
                            $sygwb=0;
                        }elseif ($num==3){
                            $me_update['mey']=$me['mey']-$us['lsk'];
                        }elseif($num==4){
                            $me_update['gwb']=$me['gwb']-$us['lsk']*$_ul['yl23']/100;
                            $me_update['zsq']=$me['zsq']-$us['lsk']*$_ul['yl24']/100;
                            $sygwb=$us['lsk']*$_ul['yl23']/100;
                            $syzsq=$us['lsk']*$_ul['yl24']/100;
                        }
                        if($me['isbd']==2){
                            //店补
                            if($_ul['yl5']>0){
                                $b6 = $_ul['yl5'];
                                edit_sql("update `member` set b6=b6+".$b6." where id=".$me['id']." ");
                                $beizhu=$_ul['yl5']."服务费";
                                $bonus_cl->bonus_laiyuan($me['id'],$me['nickname'],$us['id'],$us['nickname'],6,$b6,$beizhu);
                            }
                        }
// 								else{
// 									//店补
// 									if($_ul['yl19']>0){
// 										$b6 = $us['lsk']/100*$_ul['yl19'];
// 										edit_sql("update `member` set b6=b6+".$b6." where id=".$me['id']."");
// 										$beizhu=$_ul['yl19']."%代理提成";
// 										$bonus_cl->bonus_laiyuan($me['id'],$me['nickname'],$us['id'],$us['nickname'],6,$b6,$beizhu);
// 									}
// 								}

                        /*                             edit_sql("update `member` set zb5=1 where id=".$us['id']." ");*/
                        edit_update_cl('member',$me_update,$me['id']);
                        $_member->addbdrecord($us,$me,$us['lsk'],$sygwb,$syzsq);
                        $_member->jihuomember($us['id'],2);
                        echo "<script language=javascript>alert('会员激活完成.');window.location.href='?'</script>";
                    }else{
                        echo "<script language=javascript>alert('您的余额不足,激活失败.');window.location.href='?'</script>";
                    }
                }
            }else{
                echo "<script language=javascript>alert('您不是该会员的服务中心,无法激活该会员.');window.location.href='?'</script>";
            }
// 				}else{
// 					alert("此会员的接点人未激活","?");
// 				}
        }
    }else{
        alert("找不到当前会员信息,可能已被删除,请检查后再试.");
    }
    //echo "<script language=javascript>alert('会员激活完成.');window.location.href='?'</script>";
}

if($_POST['button4']){
    $cheuid_arr = $_GET['id'];
    $_member=new member_class();
    $bonus_cl=new bonus_class();
    if($us=$_member->getMemberbyID($cheuid_arr)){
        if($me=$_member->getMemberbyID($_SESSION['ID'])){
            if ($us['ispay']==0){
                if ($us['reid']==$me['id']){
                    if ($us['ulevel']==1){
                        if ($me['ulevel']!=6){
                            if ($me['ulevel']==2 && $me['zb10']<2){
                                $me_update['zb10']=$me['zb10']+1;
                                $_member->jihuomember($us['id']);
                                $_member->addbdrecord($us,$me,$us['lsk']);
                                edit_update_cl('member',$me_update,$me['id']);
                                echo "<script language=javascript>alert('会员激活完成.');window.location.href='?'</script>";
                            }elseif ($me['ulevel']==3 && $me['zb10']<11){
                                $me_update['zb10']=$me['zb10']+1;
                                $_member->jihuomember($us['id']);
                                $_member->addbdrecord($us,$me,$us['lsk']);
                                edit_update_cl('member',$me_update,$me['id']);
                                echo "<script language=javascript>alert('会员激活完成.');window.location.href='?'</script>";
                            }elseif ($me['ulevel']==4 && $me['zb10']<33){
                                $me_update['zb10']=$me['zb10']+1;
                                $_member->jihuomember($us['id']);
                                $_member->addbdrecord($us,$me,$us['lsk']);
                                edit_update_cl('member',$me_update,$me['id']);
                                echo "<script language=javascript>alert('会员激活完成.');window.location.href='?'</script>";
                            }else{
                                echo "<script language=javascript>alert('免费激活人数达到上限,激活失败.');window.location.href='?'</script>";
                            }
                        }else {
                            echo "<script language=javascript>alert('抱歉您不能免费激活会员,激活失败.');window.location.href='?'</script>";
                        }
                    }else{
                        echo "<script language=javascript>alert('级别错误,激活失败.');window.location.href='?'</script>";
                    }
                }
            }
        }else{
            alert("找不到当前会员信息,可能已被删除,请检查后再试.");
        }

    }
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="./awesome/css/font-awesome.min.css"/>
    <link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="./he/jquery.ui.autocomplete.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
    <title>服务中心</title>
    <SCRIPT type="text/javascript">
        function sel(){

        }
    </SCRIPT>
</head>
<body>
<?php
$title="激活会员";
include_once("./public/header_nav.html");
?>
<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
    <tr>
        <td height="10" colspan="11" align="left">
            <select name="SearchType" id="SearchType">
                <option value="1">会员编号</option>
                <option value="2">会员姓名</option>
            </select>
            <input type="text" name="SearchContent" id="SearchContent">
            <input type="submit" name="Search" id="Search" class="button_blue" value="搜  索"></td>
    </tr>
    <tr>
        <td height="10" colspan="11" align="center">报单币：<?=$my['zsq']?></td>
    </tr>
    <!--	<tr>
        <td height="10" colspan="11" align="center">电子币：<?/*=$my['gwb']*/?></td>
      </tr>-->
    <tr>
        <td align="center">会员编号</td>
        <td align="center">会员姓名</td>
        <td align="center">投资金额</td>
<!--        <td align="center">会员资格</td>-->
        <td align="center">推荐人</td>
<!--        <td align="center">联系电话</td>-->
        <td align="center">报单时间</td>
        <td align="center">状态</td>
        <td align="center">操作</td>
    </tr>
    <?php
    $pagesize = 20; //设置每页记录数
    if ($my['isbd']==2){
        $sql = "SELECT * FROM `member` WHERE bdid=".$_SESSION['ID']." and ispay=0  ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
    }else{
        $sql = "SELECT * FROM `member` WHERE reid=".$_SESSION['ID']." and ispay=0  ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
    }
    if($query = mysql_query($sql)){
        $sum = mysql_num_rows($query); //计算总记录数
    }else{
        $sum=0;
    }
    if($sum % $pagesize == 0) //计算总页数
        $total = (int)($sum/$pagesize);
    else
        $total = (int)($sum/$pagesize) + 1;
    if (isset($_GET['page'])) //获得页码
    {
        $p = (int)$_GET['page'];
    }
    else
    {
        $p = 1;
    }
    if ($p>$total){
        $p=$total;
    }
    $start = $pagesize * ($p - 1); //计算起始记录
    if ($my['isbd']==2){
        $sql = "SELECT * FROM `member` WHERE bdid=".$_SESSION['ID']." and ispay=0  ".$_SESSION['Search']."  ".$_SESSION['SearchTime']." ORDER BY rdt asc limit ".$start.",".$pagesize;
    }else{
        $sql = "SELECT * FROM `member` WHERE reid=".$_SESSION['ID']." and ispay=0  ".$_SESSION['Search']."  ".$_SESSION['SearchTime']." ORDER BY rdt asc limit ".$start.",".$pagesize;
    }
    if($query = mysql_query($sql)){
        while ($row=mysql_fetch_array($query) ){
            $ul=ulevel($row['ulevel']);

            ?>
            <tr>
                <form name="form1" method="post" action="?id=<?=$row['id']?>">
                    <td align="center"><?=$row['nickname']?></td>
                    <td align="center"><?=$row['username']?></td>
                    <td align="center"><?=$row['lsk']?></td>
   <!--                 <td align="center"><?/*=$ul['lvname']*/?></td>-->
                    <td align="center"><?=$row['rname']?></td>
                <!--    <td align="center"><?/*=$row['usertel']*/?></td>-->
                    <td align="center"><?=$row['rdt']?></td>
                    <td align="center"><?php if($row['zb5']==1){ echo "申请中";}elseif($row['ispay']==1){ echo "已激活";}?></td>
                    <td align="center">
                        <!-- --><?php /*if ($row['zb5']==0){*/?>
                        <input name="button3" type="submit" class="button_green" id="button3" value="激  活" onClick="{if(confirm('您确定要激活该会员吗?')){this.document.selform.submit();return true;}return false;}" ></input>
                        <!--        --><?php /*}*/?>

                        <input style="display:none" name="button4" type="submit" class="button_green" id="button4" value="免费激活" onClick="{if(confirm('您确定要激活该会员吗?')){this.document.selform.submit();return true;}return false;}" ></input>

                        <input name="button2" type="submit" class="button_red" id="button" value="删  除" onClick="{if(confirm('您确定要删除该会员吗?')){this.document.selform.submit();return true;}return false;}"></td>
                </form>
            </tr>

            <?php
        }
    }
    ?>

</table>
<table width="100%" border="0" class="ziti">
    <tr>
        <td align="left">&nbsp;</td>
        <td  style="padding-top: 0.4rem" align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
    </tr>
</table>

<?php include_once ("public/footer_nav.html")?>
</body>
</html>